package main.java.game.command;


import java.util.List;
import java.util.Random;

import main.java.game.Card;
import main.java.game.ChangeOfTheYear;
import main.java.game.Game;
import main.java.game.UserInterface;
import main.java.game.combatant.Monster;
import main.java.game.event.Event;
import main.java.game.location.Location;
import main.java.game.terrain.Terrain;


public class NewCard implements PlayerCommand {

	private Game game;
	
	public NewCard (Game game){
		this.game=game;
		
	}
	@Override
	public void execute() {
		List<Card> adventurePile = game.getAdventurePile();
		if(adventurePile.size()!=0){
		
			Random random= new Random();
			Integer index = game.getAdventurePile().size();
			Card card=adventurePile.get(Math.abs(random.nextInt()) % index);
				
			if(card instanceof Location){
				game.getPlayer().getLocations().add((Location)card);
				adventurePile.remove(card);
				System.out.println("The location "+card.getName()+" was added to your list of locations");
				Command command = UserInterface.mainInterface(game);
				command.execute();
				
				
			}else if(card instanceof Terrain){
				((Terrain) card).setTerrain(game);
				adventurePile.remove(card);
				System.out.println("The terrain "+card.getName()+" took effect!");
				Command command = UserInterface.mainInterface(game);
				command.execute();
				
				
			}else if(card instanceof Event){
				((Event) card).takeEffect(game);
				adventurePile.remove(card);
				System.out.println("The event "+card.getName()+" took effect!");
				Command command = UserInterface.mainInterface(game);
				command.execute();
				
			
			}else if (card instanceof Monster){
				System.out.println("The monster "+card.getName()+" is in your way! \n");
				adventurePile.remove(card);
				Command command =UserInterface.preBattleInterface(game,(Monster)card,game.getPlayer());
				command.execute();
			
			}
		
			
		}else{
		
			ChangeOfTheYear.changeOfTheYear(game);
			
		}
	}

	

}
